<?php

include 'head.php';

if(isset($_SERVER['REQUEST_METHOD'])&&strtolower($_SERVER['REQUEST_METHOD'])=='post')
{

    $param = $_REQUEST['Form'] ;
    $name = $param['name'];
    $mobile = $param['mobile'];
    $mail = $param['mail'];
    $content = $param['content'];

    if(!$_COOKIE['id'])
    {
        echo  "<script>alert('未登录，不可以留言');window.location.href='/';</script>";
    }
    else
    {
        $query = "INSERT INTO  `message` (`id`, `uid`, `nick`,`name`, `mobile`, `mail`,`content`) VALUES (NULL, '".$_COOKIE['id']."','".$_COOKIE['name']."', '".$name."', '".$mobile."','".$mail."','".$content."')";
        $result=$mysqli->query($query);
        if(!$result)
        {
            echo  "<script>alert('添加失败')</script>";
        }
        else
        {
            echo  "<script>alert('留言成功');window.location.href='/'</script>";
        }

    }
}

$result = $mysqli->query("select * from base_info WHERE id = 1");
$row = $result->fetch_assoc();

?>

    <script type="text/javascript">
		$(function(){

            $('form[name="form_submit_c"]').submit(function(){


                if(!is_login)
                {
                    alert('尚未登录,不可以操作');
                }
                var name = $('#cname').val();
                var mail = $('#cmail').val();
                var mobile = $('#mobile').val();
                var content = $('#ccontent').val();

                if(!name.length){
                    $('#cname').focus();
                    return false ;
                }

                if(!mobile.length){
                    $('#cmobile').focus();
                    return false ;
                }
                if(!mail.length){
                    $('#cmail').focus();
                    return false ;
                }

                if(!content.length){
                    $('#ccontent').focus();
                    return false ;
                }

            });
        })

    </script>
<div class="content-top">
<div class="contact">
		<div class="container">
			<div class="contact-main">
				
				<div class="contact-top">
					
					
					<div class="contact-one">
							<div class="contact_grid contact_address">
								<h5>联系方式</h5>	
								<p>电话 : <?php echo $row['phone'];?></p>
								<p>传真 : <?php echo $row['fax'];?></p>
								<p>邮箱 : <a href="malito:<?php echo $row['mail'];?>"><?php echo $row['mail'];?></a></p>
								<p>联系地址 : <?php echo $row['address'];?></p>
							</div>
					</div>
				</div>
				<div class="contact-bottom">
					<h3>接触形式</h3>
					<div class="contact-text">
                        <form action="" method="post" name="form_submit_c">
						<div class="col-md-6 contact-left-text">
							<input type="text" name="Form[name]" placeholder="姓名" id="cname" >
							<input type="text" name="Form[mobile]" placeholder="手机" id="cmobile">
                            <input type="text" name="Form[mail]" placeholder="邮箱" id="cmail">
						</div>
						<div class="col-md-6 contact-right-text">
							<textarea name="Form[content]" placeholder="正文.." id="ccontent"></textarea>
						</div>
						<div class="clearfix"></div>
						<div class="contact-but">
							<input type="submit" name="submit">
						</div>
                        </form>
					</div>
				</div>
			</div>
		</div>
	</div>	
</div>
<!-- content -->
<?php include 'foot.php';?>